import { fileURLToPath, URL } from 'node:url'

// 配置 element-plus 自动按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      // 1.配置elem采用sass配色系统
      resolvers: [ElementPlusResolver({ importStyle: 'sass'})],
    }),
  ],
  resolve: {
    alias: {
      // 实际将@转换为src路径
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 2.自动导入定制化样式文件，覆盖原本样式
        additionalData: `
          @use "@/style/element/index.scss" as *;
          @use "@/style/var.scss" as *;
        `,
      }
    }
  }
})
